package org.smile.homework01.paladin.parking;

public class ParkingLot {

    ParkingUnits[][] units;

    double totalAmount = 0;

    int row;
    int column;
    int availableNow;

    public ParkingLot(int h,int v){

        this.row = h;
        this.column = v;

        units = new ParkingUnits[h][v];

        for(int i=0; i<h; i++){
            for(int j=0; j<v; j++){
                units[i][j] = new ParkingUnits(i+1,j+1);
            }
        }

    }

    public void checkCompound(ParkingLot p){
        units = p.getUnits();
        for(int i=0; i<row; i++){
            for(int j=0; j<column; j++){
                String name = units[i][j].getName();
                Cars car = units[i][j].getCar();
                String namePlate;
                String size = units[i][j].getSize();
                if (car == null){
                    namePlate = "  无车";
                }else{
                    namePlate = car.getNamePlate();
                }

                System.out.print("  " + namePlate + " 停放于 " + name + " " + size);
            }
            System.out.println();
        }
    }


    public ParkingUnits[][] getUnits() {
        return units;
    }

    public void setUnits(ParkingUnits[][] units) {
        this.units = units;
    }

    public double getTotalAmount() {
        totalAmount = 0;
        for(int i=0; i<row; i++){
            for(int j=0; j<column; j++){
                System.out.print(units[i][j].getName() + "累计收入为：" + units[i][j].getAmount());
                totalAmount = totalAmount + units[i][j].getAmount();
            }
            System.out.println();
        }
        System.out.println("停车场总收入为：" + totalAmount);
        return totalAmount;
    }

    public void setTotalAmount(double totalAmount) {
        this.totalAmount = totalAmount;
    }

    public int getAvailableNow() {
        return availableNow;
    }

    public void setAvailableNow(int availableNow) {
        this.availableNow = availableNow;
    }
}
